package com.maybach.core.manager.impl;

import com.maybach.common.model.CarSnapDO;
import com.maybach.common.query.CarSnapQuery;
import com.maybach.core.dal.mapper.ext.CarSnapExtMapper;
import com.maybach.core.manager.CarSnapManager;
import com.maybach.util.query.support.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * Manager for CarSnap.
 */

@Component
public class CarSnapManagerImpl implements CarSnapManager{
    protected Logger log = LoggerFactory.getLogger(this.getClass());

    
    @Autowired
    protected CarSnapExtMapper carSnapExtMapper;
    /**
     * query count by query condition.
     */
    @Override
    public int countByQuery(CarSnapQuery query){
        return carSnapExtMapper.countByQuery(query);
    }

    /**
     * delete by query condition.
     */
    @Override
    public int deleteByQuery(CarSnapQuery query){
        return carSnapExtMapper.deleteByQuery(query);
    }

    /**
     * delete by primary key.
     */
    @Override
    public int deleteByPrimaryKey(CarSnapDO record){
        return carSnapExtMapper.deleteByPrimaryKey(record);
    }

    /**
     * insert selective.
     */
    @Override
    public long insertSelective(CarSnapDO record){
        return carSnapExtMapper.insertSelective(record);
    }

    /**
     * select by query condition.
     */
    @Override
    public List<CarSnapDO> selectByQuery(CarSnapQuery query){
        return carSnapExtMapper.selectByQuery(query);
    }

    /**
     * select by query condition with page.
    */
    @Override
    public PageResult<CarSnapDO> selectByQueryWithPage(CarSnapQuery query) {
        PageResult<CarSnapDO> result = new PageResult<CarSnapDO>();
        result.setPageSize(query.getPageSize());
        result.setPageNo(query.getPageNo());
        result.setTotalCount(this.countByQuery(query));
        result.setResult(this.selectByQuery(query));
        return result;
    }

    /**
     * select by primary key.
     */
    @Override
    public CarSnapDO selectByPrimaryKey(Long id){
        return carSnapExtMapper.selectByPrimaryKey(id);
    }

    @Override
    public CarSnapDO selectByLoanOrderId(Long loanOrderId) {
        CarSnapQuery carSnapQuery = new CarSnapQuery();
        CarSnapQuery.Criteria criteria = carSnapQuery.createCriteria();
        criteria.andLoanOrderIdEqualTo(loanOrderId);
        List<CarSnapDO> carSnapDOs = carSnapExtMapper.selectByQuery(carSnapQuery);
        if (null != carSnapDOs && !carSnapDOs.isEmpty()) {
            return carSnapDOs.get(0);
        } else {
            return null;
        }
    }

    /**
     * update by query condition selective.
     */
    @Override
    public int updateByQuerySelective( CarSnapDO record,  CarSnapQuery query){
        return carSnapExtMapper.updateByQuerySelective(record,  query);
    }

    /**
     * update by query condition.
     */
    @Override
    public int updateByQuery( CarSnapDO record,  CarSnapQuery query){

        return carSnapExtMapper.updateByQuery(record, query);
    }

    /**
     * update by primary key selective.
     */
    @Override
    public int updateByPrimaryKeySelective(CarSnapDO record){
        return carSnapExtMapper.updateByPrimaryKeySelective(record);
    }
}